{extend name="../layout/base"}

{block name="body"}
<div>
    <table class="layui-table" lay-even="" lay-skin="line">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>Logo</th>
            <th>应用名称</th>
            <th>标识</th>
            <th>作者</th>
            <th>版本</th>
            <th>最新版本</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="lists" id="v"}
        <tr>
            <td><img src="{$v.logo}" width="30"></td>
            <td>{$v.name}</td>
            <td>{$v.addon}</td>
            <td>{$v.author}</td>
            <td>{$v.version}</td>
            <td>{$v.new_version}</td>
            <td>{$v.update_time|date="Y-m-d H:i"}</td>
            <td> <button onclick="upgrade('{$v.addon}')" class="layui-btn layui-btn-xs">升级</button></td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>
{/block}

{block name="js"}
<script>
    var layer;
    layui.use(['layer'], function () {
        layer = layui.layer;
    });

    //升级
    function upgrade(addon) {
        layer.confirm('升级应用文件将会被更新，你确定升级应用吗？', {
            btn: ['是的','不的']
        }, function(){
            var index = layer.load(1);
            $.post("", { addon: addon },function (res) {
                layer.close(index);
                if(res.code === 1){
                    layer.msg(res.msg, {time: 1500}, function () {
                        location.reload();
                    });
                }else{
                    layer.alert(res.msg);
                }
            }).error(function (error) {
                layer.alert('500 Internal Server Error');
                layer.close(index);
            })
        }, function(){});
        return false;
    }
</script>
{/block}